/**
 *
 */
package com.wedroid.r2d2.message.handler;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.core.task.TaskExecutor;

import com.wedroid.r2d2.message.RipeMessage;

/**
 * @author lute
 */
public abstract class AsyncMessageHandler implements MessageHandler {

    protected final Logger logger = LoggerFactory.getLogger(getClass());

    @Autowired
    private TaskExecutor taskExecutor;

    /* (non-Javadoc)
     * @see com.wedroid.r2d2.message.handler.MessageHandler#handleMessage(com.wedroid.r2d2.message.RipeMessage)
     */
    public void handleMessage(final RipeMessage ripeMessage) {
        taskExecutor.execute(new Runnable() {
            /* (non-Javadoc)
             * @see java.lang.Runnable#run()
             */
            public void run() {
                handleMessageInternal(ripeMessage);
            }
        });
    }

    /**
     * @param ripeMessage
     */
    protected abstract void handleMessageInternal(RipeMessage ripeMessage);

}
